package testCase;

import com.imagotag.esl.api.LedColor;
import com.imagotag.esl.api.LedPattern;
import com.imagotag.test.Conditions;
import com.imagotag.test.LabelIdProvider;
import com.imagotag.test.TestBuilder;
import com.imagotag.test.enums.LabelCounter;
import com.imagotag.test.image.ImageGenerator;
import com.imagotag.test.image.Pattern;

import java.util.concurrent.TimeUnit;

/**
 * @projectName: bigScaleLoadTest
 * @className: Fun_extendTest
 * @description:
 * @author: JLONG
 * @date: 2024/11/13 16:34
 * @version: 1.0
 */
public class Fun_extendTest {

    // 简单的多任务循环，共循环1000次
    public static void cycleTask(TestBuilder testBuilder, LabelIdProvider labelIdProvider) {
        testBuilder
                .registerTest("Wait for all labels to be online.", test -> test.waitForLabels(labelIdProvider, Conditions.labelsOnline()))
                .waitBetweenTests("=========================<执行--计数器清零--任务>=========================", 0, TimeUnit.SECONDS)
                .registerTest("Reset Counters", test -> test.resetCounters(labelIdProvider,
                        LabelCounter.TOTAL_DISPLAY_UPDATES,
                        LabelCounter.FAILED_DISPLAY_UPDATES,
                        LabelCounter.BROWNOUT_RESETS,
                        LabelCounter.JOIN_REQUESTS_LSB,
                        LabelCounter.SCANNED_CHANNELS_LSB,
                        LabelCounter.RESYNCS_LSB,
                        LabelCounter.COUNTER_MISSED_SYNCS));
        for (int i = 1; i <= 10; i++) {
            singleTask(testBuilder, labelIdProvider, i);
        }
    }

    public static void singleTask(TestBuilder testBuilder, LabelIdProvider labelIdProvider, int times) {
        testBuilder.waitBetweenTests("=========================<" + "第" + times + "次执行循环任务>=========================", 0, TimeUnit.SECONDS)
                .registerTest("send vertical_black_red_white image", test -> test.sendImage(labelIdProvider, ImageGenerator.forPattern(Pattern.VERTICAL_BLACK_RED_WHITE), 0))
                .waitBetweenTests("Wait until the display update has finished", 30, TimeUnit.SECONDS)
                .registerTest("LED blink", test -> test.basicLedWithDuration(labelIdProvider, LedColor.RED, LedPattern.PATTERN_2, 600))
                .registerTest("refresh", test -> test.refreshLabels(labelIdProvider))
                .waitBetweenTests("Wait until the LED Blink has finished", 1, TimeUnit.MINUTES)
                .registerTest("refresh", test -> test.refreshLabels(labelIdProvider))
                .waitBetweenTests("Wait until the LED Blink has finished", 1, TimeUnit.MINUTES)
                .registerTest("stop led", test -> test.basicLed(labelIdProvider, LedColor.OFF, LedPattern.PATTERN_2, 0))

                .registerTest("send image", test -> test.sendImage(labelIdProvider, ImageGenerator.defaultImage(), 1))
                .waitBetweenTests("Wait until the display update has finished", 40, TimeUnit.SECONDS)
                .registerTest("switch", test -> test.switchPage(labelIdProvider, 0))
                .waitBetweenTests("Wait until the display update has finished", 40, TimeUnit.SECONDS)
                .registerTest("query counter", test -> test.queryCounters(labelIdProvider,
                        LabelCounter.TOTAL_DISPLAY_UPDATES,
                        LabelCounter.FAILED_DISPLAY_UPDATES,
                        LabelCounter.BROWNOUT_RESETS,
                        LabelCounter.JOIN_REQUESTS_LSB,
                        LabelCounter.SCANNED_CHANNELS_LSB,
                        LabelCounter.RESYNCS_LSB,
                        LabelCounter.COUNTER_MISSED_SYNCS
                ))
        ;
    }
}
